The enhanced HTTP client in Expeditor allows developers to quickly create code that requests data from remote servers over HTTP or HTTPS. The enhanced client wraps the standard Java URLConnectionclasses such that authenticated requests leverage the Accounts framework and HTTPS requests provide a dialog to accept server certificates.
The following code very simply demonstrates the process of creating both HTTP and HTTPS connections and printing the returned content. To access authenticated content, simply create an account with a server value similar to those provided in the sample. By doing so, any requests made using the URLConnection classes will consult the Accounts framework to provide credentials along with the request. Again, the plugin's Activator class is used to start the code.
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// two URLs to a web service running on WebSphere
String HTTP_URL = "http://dpi-portvm.atlanta.ibm.com:10000/com.ibm.rcp.support.ws.remote/services/RemoteSystem";
String HTTPS_URL = "https://dpi-portvm.atlanta.ibm.com:10002/com.ibm.rcp.support.ws.remote/services/RemoteSystem";
URL httpUrl = new URL(HTTP_URL);
URL httpsUrl = new URL(HTTPS_URL);
// create HTTP and HTTPS connections
HttpURLConnection httpConn = (HttpURLConnection) httpUrl
.openConnection();
HttpsURLConnection httpsConn = (HttpsURLConnection) httpsUrl
.openConnection();
URLConnection conns[] = { httpConn, httpsConn };
// iterate over the connections and print the received content
for (URLConnection conn : conns) {
InputStream in = null;
try {
in = conn.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(in));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} finally {
if (in != null) {
in.close();
}
}
}
}